-- BlackMarket
-- Created by cheny3 Nov/08/2016
-- 黑市摊贩

-- 初始化
function initBlackMarket(self)
    local function dealFunc()
        -- 交易
        DungeonActionM.go("deal_black_market", self.gridData:getPos());
    end

    local function stealFunc()
        -- 偷窃
        DungeonActionM.go("steal_black_market", self.gridData:getPos());
    end

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            AudioM.playFx("ui_open1");
            self:updateBuildingVisit();

            -- 打开建筑查看界面
            self:openBuildingView2(dealFunc, stealFunc,
                buildingInfo["view_text"], buildingInfo["view_text2"]);
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end